﻿<html>
	<head>
		<title>Új felhasználó</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="v-a.css" type="text/css">
	</head>
	<?php	
		session_start();
		require_once ('dbConnect.php');
		//print_r ($_POST);
		if(isset($_POST['Vissza'])) {
			$_SESSION['uzenet']="";
			header('Location: '.$_SESSION['vissza']);
			exit;
		}
		if(isset($_POST['Newuser'])) {
			$_SESSION['newusername']=$_POST['newusernameTB'];
			$_SESSION['usertipus']=$_POST['usertipusCB'];
			$_SESSION['telefonszam']=$_POST['telefonszamTB'];
			
			$result=MyDatabase::getConnection()->multi_query("CALL newuser('".$_SESSION['newusername']."','".$_SESSION['telefonszam']."','".$_SESSION['usertipus']."')");
			
			if (!$result) {
				$_SESSION['uzenet']='mysql_error: ' . MyDatabase::getConnection()->error;
			}
			else{
				$_SESSION['uzenet']='Létrehozva';
			}
		}	
	?>	
	<body>
		<table ><tr HEIGHT="10"><td WIDTH="80%">Új felhasználó</td><td WIDTH="20%"></td></tr></table>
		
		<hr>
		
		<?php 
			if(isset($_POST['Newuser'])) {printf($_SESSION['uzenet']);}
		?>
		<hr>
		<form name='newuserForm' method='post' action="newuser.php">
		<table>
		<tr>
		<td>
		<input type='submit'  class='button' name='Vissza' value='<< vissza' />
		</td>
		<td>
		<input type='submit'  class='button' name='Newuser' value='létrehoz' />
		</td>
		</tr>
		</table>
			<table width='400px'>
				<tr>
					<td>
						<label>felhasználó név:</label>
					</td>
					<td>
						<input  type='text' name='newusernameTB' maxlength='20' size='20' value='<?php 
							if(isset($_POST['newusernameTB']))
								print $_POST['newusernameTB'];
						?>'>
					</td>
				</tr>
				<tr>
					<td>
						<label>felhasználó típus:</label>
					</td>
					<td>
						<select name='usertipusCB'>
							<option value="termelo" <?php if($_SESSION['usertipus']=='termelo'){print "selected='selected' ";}?>>termelő</option>
							<option value="vasarlo" <?php if($_SESSION['usertipus']=='vasarlo'){print "selected='selected' ";}?>>vásárló</option>
						</select>
					</td>
					
				</tr>
				<tr>
					<td>
						<label>telefonszám:</label>
					</td>
					<td>
						<input  type='text' name='telefonszamTB' maxlength='20' size='20' value='<?php 
							if(isset($_POST['telefonszamTB']))
								print $_POST['telefonszamTB'];
						?>'>
					</td>
			</table>
		</form>
		
	</body>
</html>

